var path = require('path')
var fs = require('fs')
var express = require('express')
var morgan = require('morgan')
var app = express()
var port = 6065

console.log(path.join(__dirname, '../dist'))

var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' })
// setup the logger
app.use(morgan('combined', { stream: accessLogStream }))

const proxy = require('http-proxy-middleware')

const apiProxy = proxy('/api', {
    target: 'http://test1.caringnurse.cn:6060',
    changeOrigin: true,
    prependPath: true,
    pathRewrite: {
        '^/api': '/bttrs/api/v1'
    }
})

app.use('/api', apiProxy)
app.use('/static', express.static(path.join(__dirname, '../dist/static')))
app.use('/*', express.static(path.join(__dirname, '../dist/index.html')))
app.use('*', function(req, res, next) {
    res.sendFile(path.join(__dirname, '../dist/index.html'))
})
app.listen(port, () => {
    console.log('Bank Teller Trainee Web Front started at port: ' + port)
})
